//
//  UIBarButtonItem+YWFastExtension.m
//  yuwei
//
//  Created by slz on 16/11/25.
//  Copyright © 2016年 youyuwei. All rights reserved.
//

#import "UIBarButtonItem+YWFastExtension.h"

@implementation UIBarButtonItem (YWFastExtension)

+ (instancetype)itemWithImage:(NSString *)image selectImage:(NSString *)selecetImage addTarget:(id)target andAction:(SEL)sel
{
    UIButton * button = [[UIButton alloc]init];
    [button setImage:[[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selecetImage] forState:UIControlStateHighlighted];
    button.size = CGSizeMake(22, 22);
    [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithCustomView:button];
    return item;
}

+ (instancetype)itemWIthTitle:(NSString *)title addTarget:(id)target andAction:(SEL)sel{
    return [self itemWIthTitle:title addTarget:target action:sel andTitleTextAttributes:nil];
}

+ (instancetype)itemWIthTitle:(NSString *)title addTarget:(id)target action:(SEL)sel andTitleTextAttributes:(NSDictionary *)titleTextAttributes{
   
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStylePlain target:target action:sel];
    if  (titleTextAttributes == nil ){
        [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15] ,NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
    }else{
        [item setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
    }
    return item;
}
@end
